
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <errno.h>

int main(int argc, char *argv[])
{
	char GUID[40];
	int t = 0;
	// char *szTemp = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
	char *szTemp = "4xxxxxxxxxxx4xxxyxxx";
	char *szHex = "0123456789ABCDEF-";
	int nLen = strlen (szTemp);

	srand (clock());
	for (t=0; t<nLen+1; t++)
	{
		int r = rand () % 16;
		char c = ' ';   

		switch (szTemp[t])
		{
			case 'x' : { c = szHex [r]; } break;
			case 'y' : { c = szHex [r & 0x03 | 0x08]; } break;
			case '-' : { c = '-'; } break;
			case '4' : { c = '4'; } break;
		}

		GUID[t] = ( t < nLen ) ? c : 0x00;
	}

	printf ("%s\n", GUID);
	return 0;
}
